<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>配送关系管理</title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>配送区域</h1>
        <ol class="breadcrumb">
           <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">交易</a></li>
            <li class="active"><a href="#">配送关系</a></li>
            <li class="active"><a href="#">配送关系设置</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">  
                <div class="form-group form-group-xs">
			            <label for="txtDrugForm">所属地区：</label>
                        <select class="form-control"  id="area1" name="area1" disabled="disabled">
                        <option value="${area.areaId }">${area.areaName }</option>
                        </select>
                         <select class="form-control"  id="area2" name="area2">
                        </select>
                         <select class="form-control"  id="area3" name="area3">
                        </select>
			        </div>              
			        
	                <button  id="selectSee" type="button" onclick="gridSerch();" class="btn btn-success btn-sm">查&nbsp;询</button>
	            </div>			      
			</div>
		</div>
<div style="margin-top: 5px;"></div>
	<table class="jqgrid" id="gridlist"></table>
<div style="margin-top: 10px;"></div>
<div id="gridpage"></div>
<div class=" box box-warning bottongroup" id="bottongroup">
<label onclick="setDel();" class="btn btn-primary btn-sm">提 交</label>
			<label  onclick="window.history.go(-1)"   class="btn btn-danger btn-sm" >返 回</label>
		</div>
</section>
<%@ include file="/WEB-INF/component/commonJS.jsp"%>
<script type="text/javascript">

//绑定回车   id="selectSee"
$('#area1,#area2,#area3').bind('keydown', function(event) {
    if (event.keyCode == "13") {
        $('#selectSee').click();
    }
}); 

function setDel(){
	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
	if (rowIds.length <= 0) {
		$.HN.message.alert("请选择要提交的配送区域！", "消息", "warn");
		return;
	}
	var goodsCode = '${param.goodsCode}';
	var list = [];
	var areaNames="";
	for (var i=0; i<rowIds.length; i++) {
		rowId = rowIds[i];
		if("${linxuan}"=="1"){
			var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
			delRange = rowdata.delRange;
		}
		list.push({
    		"areaCode":rowId,
    		"delRange":delRange,
    		"goodsCode":goodsCode,
    		"delCompCode":"${param.compCode}"
		}); 
		if(3>i){
			areaNames+=rowdata.areaName+"<br/>";
			if(2==i){
				areaNames+="..";	
			}
		}
	}
	var delRange = "";
	$.HN.message.confirm("确定要提交以下配送区域吗？<br/>"+areaNames, '', '').on(function (e) {
        if (e) {

	$.post("${pageContext.request.contextPath}/baseGoods/setDelByComp.html", {
		"array" : json.jsonToString(list),"goodsCode":goodsCode,"compCode":"${param.compCode}"
		}, function(result) {
			if (result.success) {
				$.HN.message.alert("成功操作"+list.length+"条数据！", "消息", "success");
				gridSerch();
				//window.location.href="${ctx}/baseGoods/toProDelDrugList.html";
			} else {
				$.HN.message.alert(result.msg, "消息", "error");
			}
		}, "json"); 
        }
	}); 
}
$(document).ready(function (){
$("#area2").HNSelect({
            	parent_selector: "#area1",  url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID",defaultText: "<option value=''>请选择</option>",
                func: function () {
                    $("#area3").HNSelect({
                        parent_selector: "#area2", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID", defaultText: "<option value=''>请选择</option>",
                        		
                    });
                }
            });
	jQuery("#gridlist").jqGrid({
		url: "${ctx}/baseGoods/getDelArea.html",
	    mtype: "POST",
		datatype: "json",
		postData:{"goodsCode":"${goodsCode}","compCode":"${compCode}","goodsArea":"${param.areaCode}"},
		autowidth: true,
		shrinkToFit: true,
	//	height: 290,
	   	colNames:['配送范围','市（州）编码','市（州）名称','县（区）编码','县（区）名称'],
	   	colModel:[
            {name:'delRange',index:'delRange',width:100,hidden:true,align:"center",sorttype:false,sortable:false},
            {name:'fatherCode',index:'compName',width:100,align:"center",sorttype:false,sortable:false},
	   		{name:'fatherName',index:'areaId',width:100, align:"center",sorttype:false,sortable:false},
			{name:'areaCode',index:'areaId',key:true,width:100,align:"center", sorttype:false,sortable:false},
	   		{name:'areaName',index:'areaName',width:100,align:"center", sorttype:false,sortable:false}
	   	],
		
		 rowNum: 20,
	     rowList: [10, 20,50,100],
	     rownumbers: true,
	     multiselect:true,
	     pager: "#gridpage",
	     viewrecords: true,
			gridComplete: function(){
		//序号列宽度自适应（参数为jqgridID）
		 autoRNWidth("gridlist");
		//数据只有一条时默认选中（参数为jqgridID）
		 selectByOneData("gridlist");
		 },
	     caption: "${form.goods_code}/${form.qualityspec_name}/${form.form_name}/${form.spec_name}/${form.factor}/${form.unit_name}/${form.material_name}/${form.prod_compname}",
	     jsonReader: {
	         repeatitems: false,
	         id: "ids"
	     }
	   	
	});
	${linxuan==0?"":"$('#gridlist').hideCol('range');"}
	$(window).trigger("resize");
	$("#gridlist").jqGrid("setGridHeight", create());
	
})
 
function gridSerch(){
	var area = $.trim($("#area3").val());
	var	fatherarea = $.trim($("#area2").val());
	$("#gridlist").jqGrid('setGridParam',{  
        datatype:'json',
        postData:{"areaCode":area,
        "fatherCode":fatherarea,
        "compId":"${param.compId}",
        "goodsCode":"${param.goodsCode}"},
        page:1
    }).trigger("reloadGrid"); //重新载入  
}

</script>
</body>
</html>